#ifndef SPRITE_H
#define SPRITE_H

#include "../core/object_affiliate.h"

struct Texture {
    SDL_Texture *texture = nullptr; // 纹理
    SDL_FRect src_rect = {0}; // 源矩形
    glm::vec2 size = glm::vec2(0); // 大小
    float angle = 0; // 角度
    SDL_FlipMode flip = SDL_FLIP_NONE; // 翻转
    Texture() = default; // 默认构造函数
    explicit Texture(const std::string &file_path);
};

class Sprite : public ObjectAffiliate {
protected:
    Texture texture_; // 纹理
    bool is_finished_ = false;
    glm::vec2 percentage_ = glm::vec2(1);

public:
    static Sprite *addSpriteChild(ObjectScreen *parent, const std::string &file_path, float scale = 1.0f,
                                  Anchor anchor = Anchor::CENTER); // 创建精灵对象
    void render() override;

    virtual void setTexture(const Texture &texture); // 设置纹理

    [[nodiscard]] Texture getTexture() const { return texture_; } // 获取纹理
    void setFlip(const SDL_FlipMode flip) { texture_.flip = flip; } // 设置翻转
    void setAngle(const float angle) { texture_.angle = angle; } // 设置角度
    [[nodiscard]] SDL_FlipMode getFlipMode() const { return texture_.flip; } // 获取翻转模式
    [[nodiscard]] float getAngle() const { return texture_.angle; } // 获取角度
    void setFinished(bool is_finished) { is_finished_ = is_finished; }
    bool getFinished() const { return is_finished_; }
    void setPercentage(const glm::vec2 percentage) { percentage_ = percentage; }
    [[nodiscard]] glm::vec2 getPercentage() const { return percentage_; }
};
#endif // SPRITE_H
